package main

import "fmt"

func main() {
	a := 1
	b := 2

	fmt.Printf("a: %d, b: %d\n", a, b)

	// 变量交换
	b ^= a
	a ^= b
	b ^= a

	fmt.Printf("a: %d, b: %d\n", a, b)

	fmt.Println("=========================================================")

	fmt.Println("a+b =>", a+b)
	fmt.Println("a-b =>", a-b)
	fmt.Println("a*b =>", a*b)
	fmt.Println("a/b =>", a/b)
	fmt.Printf("a%%b => %d\n", a%b)
	fmt.Println("a^b =>", a^b)

	fmt.Println("=========================================================")

	// 自增
	b++
	// 自减
	a--
	fmt.Printf("a: %d, b: %d\n", a, b)

	fmt.Println("=========================================================")

	// 关系运算符
	fmt.Println("a==b :", a == b)
	fmt.Println("a!=b :", a != b)
	fmt.Println("a>b :", a > b)
	fmt.Println("a>=b :", a >= b)
	fmt.Println("a<b :", a < b)
	fmt.Println("a<=b :", a <= b)

	fmt.Println("=========================================================")

	// 位运算
	// 5 & 2 = 0101 & 0010 => 0000
	fmt.Printf("%d & %d => %d\n", 5, 2, 5&2)
	// 5 | 2 = 0101 | 0010 => 0111
	fmt.Printf("%d | %d => %d\n", 5, 2, 5|2)
	// 5 ^ 2 = 0101 ^ 0010 => 0111
	fmt.Printf("%d ^ %d => %d\n", 5, 2, 5^2)
	// 左移 1 << 3 = 1 * 2^3 = 8
	// 0001 => 1000
	fmt.Printf("%d << %d => %d\n", 1, 3, 1<<3)
	// 右移 8 >> 3 = 8 / 2^3 = 1
	// 1000 => 0001
	fmt.Printf("%d >> %d => %d\n", 8, 3, 8>>3)
}
